package com.yanqu.road.server.cmd.match;

import com.yanqu.road.entity.match.MatchRewardResult;
import com.yanqu.road.pb.variety.VarietyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.match.MatchModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/3/17 20:03
 */
@Cmd(code = GameProtocol.S_VARIETY_GET_WEEK_RANK_REWARD, desc = "杂艺周榜领奖")
public class GetVarietyWeekRankRewardCmd extends AbstractCommand {
    private int type;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        VarietyProto.GetWeekRankRewarReqMsg msg = VarietyProto.GetWeekRankRewarReqMsg.parseFrom(packet.getBytes());
        type = msg.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        MatchRewardResult matchRewardResult = player.getModule(MatchModule.class).getMatchRewardResult(type, false, 0);
        if (matchRewardResult.getRet() != 0) {
            VarietyProto.GetWeekRankRewarRespMsg.Builder respMsg = VarietyProto.GetWeekRankRewarRespMsg.newBuilder();
            respMsg.setRet(matchRewardResult.getRet());
            player.sendPacket(ClientProtocol.U_VARIETY_GET_WEEK_RANK_REWARD, respMsg);
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
